/*
 * @Author: chunlai
 * @Date: 2025-07-15 16:06:54
 * @LastEditTime: 2025-08-08 16:30:10
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @FilePath: \02.bldinsure\src\views\index\feecount\count.js
 * @Description: 预试算
 */
import { mapGetters } from "vuex";
import { hasProperty } from "@/methods/format.js";
import { dateToString } from "@/methods/date.js";
import { getBirthSex } from "@/methods/userinfos.js";
import { idNumCheck } from "@/translate/validate/customer";
export const feeCountMixin = {
  data() {
    return {
      userInfo: {
        name: "",
        idType: "",
        idName: "",
        idNum: "",
        sex: "",
        age: "",
        birthDate: "",
        socialInsuFlag: "",
        occupationCode: "",
        occupationClass: "",
        occupationCodeName: "",
      },
      tipsInfo: {
        name: "",
        idType: "",
        idName: "",
        idNum: "",
        sex: "",
        age: "",
        birthDate: "",
        socialInsuFlag: "",
        occupationCode: "",
        occupationClass: "",
        occupationCodeName: "",
        healthyStatus: "",
      },
      inputAlign: "right",
    };
  },
  computed: {
    ...mapGetters({
      sexList: "dictionary/sexList",
      socialSecList: "dictionary/socialSecList",
      bbrMultList: "insert/bbrMultList",
      applicant: "insert/applicant",
    }),
    disabled2Sex() {
      if (["0", "3"].includes(this.userInfo.idType.toString())) {
        return true;
      }
      return false;
    },
    ageVal() {
      if (this.userInfo.birthDate) {
        const uage = this.$GlobalFuns.userAge(this.userInfo.birthDate);
        this.changeData(
          {
            age: uage,
          },
          "0"
        );
        return uage;
      } else {
        return "";
      }
    },
    idTypeNum() {
      return this.userInfo.idNum + this.userInfo.idName;
    },
  },
  watch: {
    idTypeNum(val) {
      if (
        this.disabled2Sex &&
        this.userInfo.idNum &&
        this.userInfo.idNum.length == 18
      ) {
        let get1bs = getBirthSex(this.userInfo.idNum);
        this.changeData({
          sex: get1bs.sex,
          birthDate: get1bs.birthDate,
        });
      }
    },
  },
  methods: {
    initPreDefData() {
      if (
        hasProperty(this.formApiReg, "socialInsuFlag") &&
        !this.userInfo.socialInsuFlag
      ) {
        this.userInfo.socialInsuFlag = "Y";
      }
      // 给证件类型的赋值
      if (hasProperty(this.formApiReg, "idType")) {
        if (!this.userInfo.idType || this.idTypeList.length == 1) {
          this.changeData({
            idType: this.idTypeList[0].keyId,
            idName: this.idTypeList[0].text,
          });
        }
      }
    },
    changeIdNum() {
      if (!this.userInfo.idNum) return;
      let res = idNumCheck(this.userInfo);
      if (!res.status && res.msg) {
        return this.$toast(res.msg);
      }
      let get1bs = getBirthSex(this.userInfo.idNum);
      this.changeData({
        sex: get1bs.sex,
        birthDate: get1bs.birthDate,
      });
    },
    changeMsRadio(type, item) {
      if (type == "sex") {
        if (["0", "3"].includes(this.userInfo.idType) && this.userInfo.idNum)
          return;
      }
      let data = {};
      data[type] = item.keyId !== undefined ? item.keyId : item.value;
      this.changeData(data);
    },
    // 日期确认
    confirmBirthDate(val) {
      let date = dateToString(val);
      this.changeData({
        birthDate: date,
      });
      this.showPop = false;
    },
    // 职业确认
    confirmJob(val) {
      const str1 = val.accClass,
        str2 = this.levelName || "类",
        leiming = str1 !== void 0 && str1 !== "" ? `(${str1}${str2})` : "";
      // console.log('confirmJob---', val);
      this.changeData({
        occupationCode: val.value,
        occupationCodeName: val.name + `${leiming}`,
        occupationClass: val.accClass,
      });
    },
    changeData(data, count = "1") {
      Object.assign(this.userInfo, data);
      this.$forceUpdate();
      if (count == "1") {
        setTimeout(() => {
          this.$store.dispatch("risks/setRisks", {});
        }, 100);
      }
    },
  },
};
